// 金额转千分位
const formatPrice = (number) => {
    number = '' + number
  
    const [ integer, decimal = '' ] = number.split('.')
  
    return integer.replace(/\B(?=(\d{3})+$)/g, ',') + (decimal ? '.' + decimal : '')
  }
  
  console.log(formatPrice(123456789.3343))



function formatPrice2(num){
    let num = String(num)
    let [integer, decimal] = num.split('.')
    let index = integer.length -1
    let result = ''
    while(index > 3){
        result = ',' + integer.slice(-3) + result
        integer = integer.slice(0, index - 3)
        index -= 3
    }

    return integer + result + '.' + decimal
}